package com.youlu.campus.web.intergral.controller;

import com.youlu.campus.base.base.PageQueryRequest;
import com.youlu.campus.web.common.base.RequestContext;
import com.youlu.campus.web.intergral.service.UserIntegralLogService;
import com.youlu.campus.service.integral.UserIntegralService;
import com.yuelin.infrastructure.quantum.common.QResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 积分控制层
 * 处理用户积分的查询及积分明细记录的相关操作
 *
 * @author: zgz
 * @date: 2020/11/27 15:19
 */
@Slf4j
@RestController
public class UserIntegralController {

    @Autowired
    private UserIntegralService userIntegralService;

    @Autowired
    private UserIntegralLogService userIntegralLogService;


    /**
     * 获取当前用户的积分值
     * 从上下文获取当前用户ID，查询其对应的积分总额
     * @return 当前用户的积分值
     */
    @GetMapping("/mini-app/user/integral")
    public QResult getIntegral() {
        return QResult.success(userIntegralService.getIntegral(RequestContext.getUserId()));
    }

    /**
     * 获取积分明细列表
     * 分页查询当前用户的积分变动记录（如获取、使用等明细）
     * @param request 分页查询请求参数，包含页码、每页条数等
     * @return 积分明细分页列表
     */
    @PostMapping("/mini-app/user/integral/list")
    public QResult getUserIntegralLog(@RequestBody PageQueryRequest request) {
        return QResult.success(userIntegralLogService.getUserIntegralLog(request));
    }

}